package ClassWork5;

import java.util.ArrayList;
import java.util.List;

// 公司类
public class Company {
    private List<Dept> depts = new ArrayList<>();
    private List<Employee> employees = new ArrayList<>();

    public void addDept(Dept dept) {
        depts.add(dept);
    }

    public void removeDept(Dept dept) {
        depts.remove(dept);
    }

    public void addEmployee(Employee employee) {
        employees.add(employee);
    }

    public void removeEmployee(Employee employee) {
        employees.remove(employee);
    }

    // 输出公司员工名单
    public void printEmployeeList() {
        System.out.println("公司员工名单:");
        for (Employee employee : employees) {
            System.out.println("姓名: " + employee.getName() + ", 编号: " + employee.getId() + ", 所属部门: " + findEmployeeDept(employee).getDeptName());
        }
    }

    // 输出公司所有员工工资条
    public void printPayroll() {
        System.out.println("公司员工工资条:");
        for (Employee employee : employees) {
            System.out.println("姓名: " + employee.getName() + ", 编号: " + employee.getId() + ", 工资: " + employee.getSalary() + ", 额外收入: " + getExtraIncome(employee));
        }
    }

    // 查找员工所属部门
    public Dept findEmployeeDept(Employee employee) {
        for (Dept dept : depts) {
            if (dept.employees.contains(employee)) {
                return dept;
            }
        }
        return null;
    }

    // 获取员工额外收入（年度奖金或小时费率）
    private double getExtraIncome(Employee employee) {
        if (employee instanceof FullTimeEmployee) {
            FullTimeEmployee fullTimeEmployee = (FullTimeEmployee) employee;
            return fullTimeEmployee.getAnnualBonus();
        } else if (employee instanceof PartTimeEmployee) {
            PartTimeEmployee partTimeEmployee = (PartTimeEmployee) employee;
            return partTimeEmployee.getHourlyRate();
        }
        return 0;
    }
}
